#include "emailsrv.h"
#include "em.rpc.h"

using namespace TOB;

em_getNextSubjectRes *_getnextsubject_1_svc(em_readParam *argp, struct svc_req *rqstp)
{
	static em_getNextSubjectRes  result;
  EmailSRV em(argp->authr.nsip, std::string(argp->authr.username), 
      std::string(argp->authr.password));
  std::string header;
  result.code = em.getNextSubject(argp->letterId, header);
  header = header.substr(0, HEADERLENGTH-1);
  memcpy(result.header, header.c_str(), header.size()+1);
	return &result;
}

em_readLetterRes *_readletter_1_svc(em_readParam *argp, struct svc_req *rqstp)
{
	static em_readLetterRes  result;
  EmailSRV em(argp->authr.nsip, std::string(argp->authr.username), 
      std::string(argp->authr.password));
  std::string body;
  result.code = em.readLetter(argp->letterId, body);
  body = body.substr(0, HEADERLENGTH-1);
  memcpy(result.body, body.c_str(), body.size()+1);
	return &result;
}

u_int *_sendletter_1_svc(em_sendLetterParam *argp, struct svc_req *rqstp)
{
	static u_int  result;
  EmailSRV em(argp->authr.nsip, std::string(argp->authr.username), 
      std::string(argp->authr.password));
  result = em.sendLetter(std::string(argp->header), std::string(argp->body));
	return &result;
}

u_int *_expandmail_1_svc(em_authr *argp, struct svc_req *rqstp)
{
	static u_int result;
  EmailSRV em(argp->nsip, std::string(argp->username), std::string(argp->password));
  result = em.expandMail();
	return &result;
}
